package com.hlf.modules.merchant.bank.service.impl;

import com.hlf.common.constants.Constants;
import com.hlf.common.utils.IdWorkerFactory;
import com.hlf.modules.merchant.bank.entity.BankCard;
import com.hlf.modules.merchant.bank.mapper.BankCardMapper;
import com.hlf.modules.merchant.bank.service.BankCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BankCardServiceImpl implements BankCardService {

	@Autowired
	private BankCardMapper bankCardMapper;
	
	@Override
	public String deleteByPrimaryKey(Long id) {
		bankCardMapper.deleteByPrimaryKey(id);
		return Constants.DEFAULT_MSG_SUCCESS;
	}

	@Override
	public String insert(BankCard record) {
		bankCardMapper.insert(record);
		return Constants.DEFAULT_MSG_SUCCESS;
	}

	@Override
	public String insertSelective(BankCard record) {
		bankCardMapper.insertSelective(record);
		return Constants.DEFAULT_MSG_SUCCESS;
	}

	@Override
	public BankCard selectByPrimaryKey(Long id) {
		return bankCardMapper.selectByPrimaryKey(id);
	}

	@Override
	public String updateByPrimaryKeySelective(BankCard record) {
		bankCardMapper.updateByPrimaryKeySelective(record);
		return Constants.DEFAULT_MSG_SUCCESS;
	}

	@Override
	public String updateByPrimaryKey(BankCard record) {
		bankCardMapper.updateByPrimaryKey(record);
		return Constants.DEFAULT_MSG_SUCCESS;
	}

	@Override
	public List<BankCard> findListbyUserId(Long userId) {
		return bankCardMapper.findListbyUserId(userId);
	}

	@Override
	public String updateCnapsCodeById(Long id,String cnapsCode) {
		bankCardMapper.updateCnapsCodeById(id,cnapsCode);
		return Constants.DEFAULT_MSG_SUCCESS;
	}

	@Override
	public String save(BankCard bankCard) {
	    if (bankCard.getId() != null) {
		    bankCard.setId(IdWorkerFactory.nextId());
        }
		bankCard.setInsertBy(bankCard.getLastUpdateBy());
		bankCard.setInsertDate(bankCard.getLastUpdateDate());
		bankCardMapper.insertSelective(bankCard);
		return Constants.DEFAULT_MSG_SUCCESS;
	}

}
